package com.example.mapper;

import com.example.pojo.*;
import com.example.pojo.Class;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface TeacherFirstPageMapper {

    Teacher select(String username);

    void updateInfo(Teacher teacher);

    LoginMsg selectUpdated(Teacher teacher);

    @Select("select distinct classes.class_id,class_name from teacher_classes,classes where teacher_id = #{teacherId} and classes.class_id=teacher_classes.class_id order by class_id ")
    List<Class> searchClass(Integer teacherId);

    @Select("select distinct subject_name from teacher_classes where teacher_id=#{teacherId} and class_id=(select class_id from classes where class_name=#{className}) ")
    List<String> searchSubject(Integer teacherId,String className);

    @Select("select semester from teacher_classes where teacher_id=#{teacherId} and class_id=(select class_id from classes where class_name=#{className}) and subject_name=#{subjectName}")
    List<String> searchSemester(Integer teacherId, String className, String subjectName);

    @Insert(" insert into grades(student_id, subject_id, usual_score,midterm_score,final_score,score,earn_credit)   values (#{studentId},(select subject_id from subjects where subject_name=#{subjectName}),#{usualScore},#{midtermScore},#{finalScore},#{score},#{earnCredit})")
    void insertSingleScore(Score score);

    @Select("select count(1)>0 from students where class_id=(select class_id from classes where class_name=#{className}) and student_id=#{studentId}")
    boolean isExistStudent(Score score);

    @Select("select count(1)>0 from grades where student_id=#{studentId} and subject_id=(select subject_id from subjects where subject_name=#{subjectName})")
    boolean isExistScore(Score score);

    void batchInsertScores(List<Score> scoreList);


    Percentage inqueryPercentage(Score score);

    @Select("select credit from subjects where subject_name=#{subjectName}")
    Integer inqueryCredit(Score score);
    @Select("select teacher_id from teachers where username=#{username}")
    Integer inqueryTeacherId(String username);

    @Select("select count(1)>0 from teacher_classes where teacher_id= #{teacherId} and class_id=(select class_id from classes where class_name= #{className}) and subject_name= #{subjectName}")
    boolean isExistManageClass(Score score);
}
